"""This module processes the xml config file for deemon.

It create a dictionary with the keys for fields to the several methods used
in Deemon files.

Still there are some improvements to do. But its will 
occours in future versions.

"""

from xml.dom.minidom import *

class Config(object):
    """This class processes the xml tree which contains the deemon parameters. """
    
    data = {}
    campos = []
    
    def __init__(self, nomeArquivo):
        """This __init__ processes the xml file and capture the tags for
        each field in xml tree.
    
        """
        
        self.document = parse(nomeArquivo)     # dispensavel, pode-se ficar soh com o cluster
        self.cluster = self.document.getElementsByTagName('Deemon')[0]
    
    def getData(self, nomes):
        """ Get a list of fields to process. """
        
        for n in nomes:
            self.campos.append(self.cluster.getElementsByTagName(n)[0])
            
        for element in self.campos:
            self.seeFields(element)
            
        return self.data

    def seeFields(self, campo):
        """ Set the dict pairs using the information in xml tree. """
        
        temp = []
        child = campo.childNodes
        
        for i in child:                 # select the elements nodes
            if i.nodeType == 1:
                temp.append(i)
         
        for i in temp:
            k = i.attributes.items()    # make de dict
            self.data[k[0][1]] = k[1][1]